<template>
    <el-dialog title="登录" width="35%" :visible="true">
        <el-form :model="form" label-width="80px">
            <el-form-item label="用户名">
                <el-input v-model="form.userName" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="form.password" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button>取 消</el-button>
            <el-button type="primary" @click="onLogin">登 录</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import {login} from "@/api/login";

    export default {
        name: "loginIndex",
        data() {
            return {
                form: {userName: 'zs', password: '123'}
            }
        },
        methods: {
            onLogin() {
                login(this.form).then(resp => {
                    if (resp.code == 200) {
                        this.$message.success('登录成功');
                        sessionStorage.setItem("token", JSON.stringify(resp.data))
                        this.$router.push('/index');
                    }

                })
            }
        }
    }
</script>

<style scoped>

</style>